﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FireStarterModeller.BO;
using FireStarterModeller.Test;
using NUnit.Framework;
using NUnit.Framework.Constraints;
 

namespace Firestarter.DB_DomainModel.Logic.Test
{
    [TestFixture]
    public class TestPropertyTypeStorer :  TestBase
    {
        [Test]
        public void Test_Construct()
        {
            //---------------Set up test pack-------------------
            DMSolution solution = new DMSolution();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            PropertyTypeStorer propertyTypeStorer = new PropertyTypeStorer(solution);
            //---------------Test Result -----------------------
            Assert.IsInstanceOf(typeof(IPropertyTypeStorer), propertyTypeStorer);
            Assert.AreSame(solution, propertyTypeStorer.Solution);
        }

        [Test]
        public void Test_GetDMPropertyType_WhenExistsInSolution_ReturnsPropertyType()
        {
            //---------------Set up test pack-------------------
            DMSolution solution = new DMSolution();
            string assemblyName = TestUtilsShared.GetRandomString();
            string propertyTypeName = TestUtilsShared.GetRandomString();
            DMPropertyType expectedPropertyType = new DMPropertyType() { AssemblyName = assemblyName, PropertyTypeName = propertyTypeName };
            solution.PropertyTypes.Add(expectedPropertyType);
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorer(solution);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            DMPropertyType propertyType = propertyTypeStorer.GetDMPropertyType(assemblyName, propertyTypeName);
            //---------------Test Result -----------------------
            Assert.AreSame(expectedPropertyType, propertyType);
        }

        [Test]
        public void Test_GetDMPropertyType_WhenNotExistsInSolution_ReturnsNewPropertyType()
        {
            //---------------Set up test pack-------------------
            DMSolution solution = new DMSolution();
            string assemblyName = TestUtilsShared.GetRandomString();
            string propertyTypeName = TestUtilsShared.GetRandomString();
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorer(solution);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            DMPropertyType propertyType = propertyTypeStorer.GetDMPropertyType(assemblyName, propertyTypeName);
            //---------------Test Result -----------------------
            Assert.IsNotNull(propertyType);
            Assert.AreEqual(assemblyName, propertyType.AssemblyName);
            Assert.AreEqual(propertyTypeName, propertyType.PropertyTypeName);
        }
        
    }
}
